var mysql = require('mysql');
var connection = mysql.createConnection({
    host: 'localhost',
    port:3306,
    user: 'root',
    password: 'root',
    database: 'crud'
});

connection.connect((err) => {
    if (!err) {
        console.log('数据库链接成功');
    }else{
        console.log("数据库链接失败");
    }
});

function select(sql){
    return new Promise((resolve,reject)=>{
        connection.query(sql,(err,data)=>{
            resolve(data);
        })
    })
}
function list(sql){
    return new Promise((resolve,reject)=>{
        connection.query(sql,(err,data)=>{
            resolve(data);
        })
    })
}
module.exports = {
    select,
    list
}